package site.microkang.house.service;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import site.microkang.house.mapper.TalentIdentificationMapper;
import site.microkang.house.model.dto.TalentIdentificationDto;
import site.microkang.house.model.entity.TalentIdentificationEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * @author liukang
 * @date 2021/3/19 21:35
 */
@Service
@Transactional(readOnly = true)
public class TalentIdentificationService {
    @Autowired(required = false)
    private TalentIdentificationMapper talentIdentificationMapper;

    /**
     * 条件查询数据
     * @param dto
     * @return
     */
    public List<TalentIdentificationDto> selectList(TalentIdentificationDto dto) {
        QueryWrapper<TalentIdentificationEntity> queryWrapper = new QueryWrapper<>();
        List<TalentIdentificationEntity> list = talentIdentificationMapper.selectList(queryWrapper);
        List<TalentIdentificationDto> dtos = new ArrayList<>();
        list.forEach(v -> {
            dtos.add(TalentIdentificationDto.builder()
                    .idCardNumber(v.getIdCardNumber())
                    .identifyAddress(v.getIdentifyAddress())
                    .identifyResult(v.getIdentifyResult())
                    .name(v.getName())
                    .officeAddress(v.getOfficeAddress())
                    .talentNo(v.getTalentNo())
                    .talentType(v.getTalentType())
                    .identifyDate(DateUtil.format(v.getIdentifyDate(), "yyyy-MM-dd"))
                    .build());
        });
        return dtos;
    }

    @Transactional(readOnly = false)
    public int insert(TalentIdentificationEntity entity) {
        int insert = talentIdentificationMapper.insert(entity);
        return insert;
    }
}
